//
//  WRYThemeCell.m
//  BaiSiBuJie
//
//  Created by wry on 16/5/3.
//  Copyright © 2016年 WRY. All rights reserved.
//

#import "WRYThemeCell.h"
#import "WRYThemeItem.h"
#import "WRYTopView.h"
#import "WRYThemeViewModal.h"
#import "WRYPictureView.h"
#import "WRYVoiceView.h"
#import "WRYVideoView.h"
#import "WRYHotCommentView.h"
#import "WRYBottomView.h"
@interface WRYThemeCell ()

@property(nonatomic,weak) WRYTopView * topView;//顶部view
@property(nonatomic,weak) WRYPictureView * pictureView;//PictureView 中间view
@property(nonatomic,weak) WRYVoiceView * voiceView;//PictureView 中间view
@property(nonatomic,weak) WRYVideoView * videoView;//PictureView 中间view
@property(nonatomic,weak) WRYHotCommentView * hotCommentView;//最热评论
@property(nonatomic,weak) WRYBottomView * bottomView;//底部view

@end

@implementation WRYThemeCell
-(void)setFrame:(CGRect)frame
{
    frame.size.height-=10;//必须在super前面写
    frame.origin.y+=10;
    [super setFrame:frame];
}



#pragma mark - 设置cell数据


-(void)setVm:(WRYThemeViewModal *)vm
{
    _vm=vm;
    
    // 设置topView的frame
    _topView.frame=vm.topViewFrame;
    _topView.item=vm.item;
/*------------------注释----------------------*/

    //设置middleView样式
    if (vm.item.type == WRYThemeTypePicture) {//图片
        _videoView.hidden=YES;
        _voiceView.hidden=YES;
        _pictureView.hidden=NO;
        _pictureView.frame=vm.pictureViewFrame;
        _pictureView.item=vm.item;
    
    }else if (vm.item.type == WRYThemeTypeVoice){//音频
        _videoView.hidden=YES;
        _voiceView.hidden=NO;
        _pictureView.hidden=YES;
        _voiceView.item=vm.item;
        _voiceView.frame=vm.pictureViewFrame;
        
    
    }else if (vm.item.type == WRYThemeTypeVideo){//视频
        _videoView.hidden=NO;
        _voiceView.hidden=YES;
        _pictureView.hidden=YES;
        _videoView.item=vm.item;
        _videoView.frame=vm.pictureViewFrame;
        
        
    }else {//其他
        _videoView.hidden=YES;
        _voiceView.hidden=YES;
        _pictureView.hidden=YES;
    }
/*------------------注释----------------------*/
    //hotCommentView
    if (vm.item.hotcommentItem) {
        //注意必须判断显示和不显示,因为cell有复用.
        _hotCommentView.hidden=NO;
        _hotCommentView.frame=vm.hotCommentViewFrame;
        _hotCommentView.item=vm.item;
    }else{
        _hotCommentView.hidden=YES;
    }
    
    //bottomView
    _bottomView.item=vm.item;
    _bottomView.frame=vm.bottomViewFrame;
}

#pragma mark -初始化cell

// 通过代码初始化cell就会调用这个
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        // 不要cell选中样式,注意：只是选中cell没有效果，但是cell还是可以选中
        
        self.selectionStyle=UITableViewCellSelectionStyleNone;
        // 设置cell背景图片
        UIImage*img=[UIImage imageNamed:@"mainCellBackground"];
        img=[img stretchableImageWithLeftCapWidth:WRYScreenW*0.5 topCapHeight:self.height*0.5];
        self.backgroundView=[[UIImageView alloc]initWithImage:img];
        
       
        // 1.添加顶部view
        WRYTopView * topView=[WRYTopView loadFromNib];
    
        [self.contentView addSubview:topView];
       _topView = topView;//不要漏掉这一步,给属性赋值--->否则没有数据;!!!!!!!!!!!
        
        // 2.中间view(图片，音频，视频) 根据内容去展示
        
        //2.1
        WRYPictureView *pictureView=[WRYPictureView loadFromNib];
        self.pictureView=pictureView;
        [self.contentView addSubview:pictureView];
        //2.2
        WRYVoiceView *voiceView=[WRYVoiceView loadFromNib];
        _voiceView=voiceView;
        [self.contentView addSubview:voiceView];
        //2.3
        WRYVideoView * videoView=[WRYVideoView loadFromNib];
        _videoView=videoView;
        [self.contentView addSubview:videoView];
        
        
        // 3.最热评论 根据内容去展示
        WRYHotCommentView * hotCommentView=[WRYHotCommentView loadFromNib];
        _hotCommentView=hotCommentView;
        [self.contentView addSubview:hotCommentView];
        
        // 4.底部view
        WRYBottomView * bottomView=[WRYBottomView loadFromNib];
        _bottomView=bottomView;
        [self.contentView addSubview:bottomView];
    }
    return self;

}









@end
